<?php

namespace app\api\controller;

use app\services\ConfigService;
use app\services\EmailService;
use app\services\ModelService;
use app\services\MusicService;
use app\services\NameCardService;
use app\services\OrderService;
use app\services\UpLineService;
use app\services\UserCouponService;
use app\services\UserLevelService;
use app\services\UserPropertyService;
use app\services\UserService;
use app\services\UserTeamService;
use app\services\WechatMiniProgramShippingService;
use EasyWeChat\Factory;
use Overtrue\Pinyin\MemoryFileDictLoader;
use Overtrue\Pinyin\Pinyin;
use plugin\admin\app\model\Area;
use plugin\admin\app\model\Music;
use plugin\admin\app\model\Order;
use plugin\admin\app\model\Rule;
use plugin\admin\app\model\UserProfile;
use support\Cache;
use support\Db;
use support\EasyWechatFactory;
use support\KuaidiBird;
use support\Request;

class TestController
{
    public function test(Request $request)
    {
        $id = $request->get('id');
        Db::beginTransaction();
        try {
            $config = ConfigService::getByGroup('wechat');
            $app = Factory::miniProgram([
                'app_id' => $config['wechat_app_id'],
                'secret' => $config['wechat_app_secret'],
                'response_type' => 'array'
            ]);
            $response = $app->app_code->get('/pages/order/info?merchant_trade_no=NOA6DMBS1YCKR2786', [
                'env_version' => 'trial',
            ]);
            if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
                $response->saveAs(public_path() . '/mini_program_qrcode', 'testtest.png');
                $inviteQrcodeUrl = full_url('/mini_program_qrcode/' . 'testtest.png');

                return $inviteQrcodeUrl;
            }

            Db::commit();

            return '执行成功';
        } catch (\Exception $e) {
            Db::rollBack();
            return $e->getMessage() . $e->getTraceAsString();
        }
    }
}